/**
 * Created by admin on 2017/10/26.
 */
$(document).ready(function () {
    $("form").submit(function () {
        return false;
    });
    var VAL = {
        NORMAL: "0000000",
        EVT_USER: $("#userId").text(),
        T_FBPBISOPE: 'FBPBISOPE',
        T_FBPBISTOL: 'FBPBISTOL',
        T_FBPBISPTH: 'FBPBISPTH',
        T_FIPINQBOX: 'FIPINQBOX',
        T_FBPMDLDEF: "FBPMDLDEF",
        T_FPPWHSOPE: "FPPWHSOPE",
        T_FBPBISDAT: "FBPBISDAT",
        T_FPPMOVEIN: 'FPPMOVEIN',
        T_FIPINQSHT: "FIPINQSHT",
        T_FPPMOVEOUT: 'FPPMOVEOUT',
        T_FPPMVINCCL :'FPPMVINCCL',
        DISABLED_ATTR: {
            'disabled': true
        },
        ENABLED_ATTR: {
            'disabled': false
        }
    };
    var domObj = {
        login_btn: $("#login_btn"),
        reg_btn: $("#reg_btn"),
        logof_btn: $("#logof_btn"),
        query_btn: $("#query_btn"),
        //in
        prdIdIn: $("#prdIdInTxt"),
        BatchNoIn: $("#BatchNoInTxt"),
        BatchCntIn: $("#BatchCntInTxt"),
        NeedTestCntIn: $("#NeedTestCntInTxt"),
        //reg
        prdIdReg: $("#prdIdRegTxt"),
        tpRdo: $("#tpRdo"),
        dxRdo: $("#dxRdo"),
        wgRdo: $("#wgRdo"),
        BatchNoRegTxt: $("#BatchNoRegTxt"),
        BatchCntReg: $("#BatchCntRegTxt"),
        TestCntReg: $("#TestCntRegTxt"),
        abnCntReg: $("#abnCntRegTxt"),
        okRegRdo: $("#okRegRdo"),
        ngRegRdo: $("#ngRegRdo"),
        $defectCode: $("#defectCode"),
        //of
        prdIdOf: $("#prdIdOfTxt"),
        BatchNoOf: $("#BatchNoOfTxt"),
        BatchCntOf: $("#BatchCntOfTxt"),
        tpTestCntOf: $("#tpTestCntOfTxt"),
        dxTestCntOf: $("#dxTestCntOfTxt"),
        wgTestCntOf: $("#wgTestCntOfTxt"),
        tpAbnCntOf: $("#tpAbnCntOfTxt"),
        dxAbnCntOf: $("#dxAbnCntOfTxt"),
        wgAbnCntOf: $("#wgAbnCntOfTxt"),
        okOfRdo: $("#okOfRdo"),
        ngChRdo: $("#ngChRdo"),
        ngOfRdo: $("#ngOfRdo"),
        chPrdSeqId: $("#chPrdSeqId"),
        $chOpeIdFk : $("#chOpeIdFk"),

        /*okOfRdo: $("#okOfRdo"),
        ngOfRdo: $("#ngOfRdo"),
        nxOpe: $("#nxOpeSel"),*/
        //common
       /* $factorySite: $("#factorySite"),
        $factoryId: $("#factoryId"),*/
        $bayId: $("#bayId"),
        $toolIdFk: $("#toolIdFk"),
        $woCateSel: $("#woCateSel"),
        $woIdFk: $("#woIdFk"),
        $opeIdFk: $("#opeIdFk"),
        $prdSeqId: $("#prdSeqId"),
        $lotId: $("#lotId"),
        $productId: $("#productId"),
        $mdlIdFk: $("#mdlIdFk"),
        $bayIdFk: $("#bayIdFk"),
        $pathId: $("#pathId"),
        $cr_ope_no: $("#cr_ope_no"),
        grids: {
            $prdListDiv: $("#prdListDiv"),
            $prdListGrd: $("#prdListGrd"),
            $prdListPg: $("#prdListPg"),

            $chPrdListDiv: $("#chPrdListDiv"),
            $chPrdListGrd: $("#chPrdListGrd"),
            $chPrdListPg : $("#chPrdListPg"),
        },
        dialogs: {
            $DFCodeDialog: $("#DFCodeDialog"),
            $defectListDiv: $("#defectListDiv"),
            $defectListGrd: $("#defectListGrd"),
            $defectListPg: $("#defectListPg"),
            $defectCode_sureBtn: $("#defectCode_sureBtn"),

        }

    }

    function initInner() {
        domObj.grids.$prdListGrd
            .jqGrid({
                url: "",
                datatype: "local",
                mtype: "POST",
                height: 400,
                width: $("#prdListDiv").width() * 0.99,
                autowidth: false,
                shrinkToFit: true,
                resizable: true,
                loadonce: true,
                viewrecords: true,
                rownumbers: true,
                rowNum: 20,
                emptyrecords: true,
                colModel: [
                    {
                        name: 'wo_id',
                        index: 'wo_id',
                        label: '工单号',
                        width: 130
                    }, {
                        name: 'prd_seq_id',
                        index: 'prd_seq_id',
                        label: '屏体代码',
                        width: 60
                    }, {
                        name: 'prd_stat',
                        index: 'prd_stat',
                        label: '屏体状态',
                        width: 100
                    }, {
                        name: 'mdl_id_fk',
                        index: 'mdl_id_fk',
                        label: '产品型号',
                        width: 150
                    }, {
                        name: 'ope_id',
                        index: 'ope_id',
                        label: '站点代码',
                        width: 100
                    }, {
                        name: 'lot_id',
                        index: 'lot_id',
                        label: '批次号',
                        width: 140
                    }],
                pager: "#prdListPg",
            });
        domObj.grids.$chPrdListGrd
            .jqGrid({
                url: "",
                datatype: "local",
                mtype: "POST",
                height: 100,
                width: ($(".container-fluid").width()-635) * 0.99,
                autowidth: false,
                shrinkToFit: true,
                resizable: true,
                loadonce: true,
                viewrecords: true,
                rownumbers: true,
                rowNum: 20,
                emptyrecords: true,
                colModel: [
                    {
                        name: 'prd_seq_id',
                        index: 'prd_seq_id',
                        label: '屏体ID',
                        width: 100
                    }, {
                        name: 'wo_id_fk',
                        index: 'wo_id_fk',
                        label: '工单号',
                        width: 100
                    }, {
                        name: 'prd_stat',
                        index: 'prd_stat',
                        label: '屏体状态',
                        width: 100
                    }, {
                        name: 'mdl_id_fk',
                        index: 'mdl_id_fk',
                        label: '产品型号',
                        width: 150
                    }, {
                        name: 'ext_4',
                        index: 'ext_4',
                        label: '电讯检测结果',
                        width: 100
                    }, {
                        name: 'ext_6',
                        index: 'ext_6',
                        label: '外观检测结果',
                        width: 140
                    }],
                pager: "#chPrdListPg",
            });
        domObj.dialogs.$defectListGrd
            .jqGrid({
                url: "",
                datatype: "local",
                mtype: "POST",
                height: 400,
                width: 800,//($("#defectListDiv").width()) * 0.99,
                autowidth: false,
                shrinkToFit: true,
                resizable: true,
                loadonce: true,
                viewrecords: true,
                rownumbers: true,
                rowNum: 20,
                emptyrecords: true,
                colModel: [
                    {
                        name: 'data_id',
                        index: 'data_id',
                        label: '缺陷代码',
                        width: 60
                    }, {
                        name: 'data_ext',
                        index: 'data_ext',
                        label: '缺陷代码描述',
                        width: 130
                    }],
            });
    }
    var ope_no;
    var toolFunc = {
        clean_func: function () {
            $("input").val("");
            $("select").empty();
            $("select").val("").trigger("change");
            $("#prdListGrd").jqGrid('clearGridData');
            $("#chPrdListGrd").jqGrid('clearGridData');
        },
        addSelectArr:function($selectDom,arr,valProp,txtProp,checkExistedFlg,firstSpace){
            var i,options;
            if(!arr){
                return false;
            }
            if(!$.isArray(arr)){
                arr = [arr];
            }
            $selectDom.empty();
            if(firstSpace === true){
                $selectDom.append("<option ></option>");
            }
            txtProp = (typeof(txtProp)==="undefined" ? valProp :txtProp);
            if(typeof(checkExistedFlg)!=="undefined" && checkExistedFlg){
                for(i=0;i<arr.length;i++){
                    this.addSelect($selectDom, arr[i][valProp], arr[i][txtProp]);
                }
            }else{
                /***
                 * 提高执行效率，避免多次给Select添加元素
                 * 使用array.join("") 代替"+"拼接字符串
                 */
                options = [];
                for(i=0;i<arr.length;i++){
                    options[i] = "<option value ="+ arr[i][valProp] +">" + arr[i][txtProp] +":"+ arr[i].cr_ope_desc+ "</option>";
                }
                $selectDom.append(options.join(""));
            }
            $selectDom.select2({
                theme : "bootstrap"
            });
        },
        query_func: function () {
            var prdSeqId = $.trim(domObj.prdIdIn.val());
            if (!prdSeqId) {
                showErrorDialog("", "屏体ID不能为空");
                return false;
            }
            var inObj = {
                trx_id: VAL.T_FIPINQSHT,
                action_flg: 'Q',
                prd_seq_id: prdSeqId
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                if (outObj.toolg_id_fk!= "$FQC") {
                    showErrorDialog("", "此批次屏体不在FQC站点");
                    return false;
                }
                if(outObj.smp_cnt==null){
                    showErrorDialog("", "请设定该产品FQC抽检规则");
                    return false;
                }
               /* domObj.$factorySite.val(outObj.fab_site_id_fk);
                domObj.$factoryId.val(outObj.fab_id_fk);*/
                domObj.$woIdFk.val(outObj.wo_id_fk);
               /* domObj.$woCateSel.val(outObj.wo_cate);*/
                domObj.$opeIdFk.val(outObj.ope_id_fk);
                domObj.$toolIdFk.val(outObj.toolByope);
                domObj.$mdlIdFk.val(outObj.mdl_id_fk);
                domObj.$bayIdFk.val(outObj.bay_id);
                domObj.$pathId.val(outObj.cr_path_id_fk);
                domObj.BatchNoIn.val(outObj.lot_id);
                domObj.BatchCntIn.val(outObj.lot_cnt);
                domObj.NeedTestCntIn.val(outObj.smp_cnt);
                var inObjLot = {
                    trx_id: VAL.T_FIPINQSHT,
                    action_flg: 'L',
                    prd_seq_id: prdSeqId
                };
                var outObjLot = comTrxSubSendPostJson(inObjLot);
                if (outObjLot.rtn_code == VAL.NORMAL) {
                    setGridInfo(outObjLot.oary3, "#prdListGrd");
                }
            }

        },
        queryCnt_func: function () {
            domObj.$defectCode.val("");
            var prdSeqId = domObj.prdIdReg.val().trim();
            if (!prdSeqId) {
                showErrorDialog("", "屏体ID不能为空");
                return false;
            }
            var testCate = "T";
            if (domObj.tpRdo.attr("checked") == "checked") {
                testCate = "T";
            } else if (domObj.dxRdo.attr("checked") == "checked") {
                testCate = "D";
            } else if (domObj.wgRdo.attr("checked") == "checked") {
                testCate = "W";
            }
            var inObj = {
                trx_id: VAL.T_FIPINQSHT,
                action_flg: 'Q',
                prd_seq_id: prdSeqId,
                test_cate: testCate
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                if (outObj.toolg_id_fk!= "$FQC") {
                    showErrorDialog("", "此批次屏体不在FQC站点");
                    return false;
                }
                if (outObj.prd_stat != "INPR") {
                    showErrorDialog("", "此批次屏体还没有入账");
                    return false;
                }
              /*  domObj.$factorySite.val(outObj.fab_site_id_fk);
                domObj.$factoryId.val(outObj.fab_id_fk);*/
                domObj.$woIdFk.val(outObj.wo_id_fk);
                domObj.$woCateSel.val(outObj.wo_cate);
                domObj.$opeIdFk.val(outObj.ope_id_fk);
                domObj.$toolIdFk.val(outObj.toolByope);
                domObj.$mdlIdFk.val(outObj.mdl_id_fk);
                domObj.BatchNoRegTxt.val(outObj.lot_id);
                domObj.$bayIdFk.val(outObj.bay_id);
                domObj.$pathId.val(outObj.cr_path_id_fk);
                domObj.BatchCntReg.val(outObj.lot_cnt);
                domObj.TestCntReg.val(outObj.test_cnt);
                domObj.abnCntReg.val(outObj.abn_cnt);
            }
        },
        queryOf_func: function () {
            var prdSeqId = domObj.prdIdOf.val().trim();
            if (!prdSeqId) {
                showErrorDialog("", "屏体ID不能为空");
                return false;
            }
            var inObj = {
                trx_id: VAL.T_FIPINQSHT,
                action_flg: 'Q',
                prd_seq_id: prdSeqId,
                query_type: "O"
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                ope_no = outObj.cr_ope_no_fk;
                if (outObj.toolg_id_fk!= "$FQC") {
                    showErrorDialog("", "此批次屏体不在FQC站点");
                    return false;
                }
                if (outObj.prd_stat != "INPR") {
                    showErrorDialog("", "此批次屏体还没有入账");
                    return false;
                }
              /*  domObj.$factorySite.val(outObj.fab_site_id_fk);
                domObj.$factoryId.val(outObj.fab_id_fk);*/
                domObj.$cr_ope_no .val(outObj.cr_ope_no) ;
                domObj.$woIdFk.val(outObj.wo_id_fk);
                domObj.$woCateSel.val(outObj.wo_cate);
                domObj.$opeIdFk.val(outObj.ope_id_fk);
                domObj.$toolIdFk.val(outObj.toolByope);
                domObj.$bayIdFk.val(outObj.bay_id);
                domObj.$mdlIdFk.val(outObj.mdl_id_fk);
                domObj.$pathId.val(outObj.cr_path_id_fk);
                domObj.BatchNoOf.val(outObj.lot_id);
                domObj.BatchCntOf.val(outObj.lot_cnt);
                domObj.tpTestCntOf.val(outObj.tp_test_cnt);
                domObj.dxTestCntOf.val(outObj.dx_test_cnt);
                domObj.wgTestCntOf.val(outObj.wg_test_cnt);
                domObj.tpAbnCntOf.val(outObj.tp_abn_cnt);
                domObj.dxAbnCntOf.val(outObj.dx_abn_cnt);
                domObj.wgAbnCntOf.val(outObj.wg_abn_cnt);
                setGridInfo(outObj.oary_table, domObj.grids.$chPrdListGrd);
                //判断批次中的玻璃是不是只能批退了


                if(outObj.showflag == true){//为true
                     $("#okOfRdo").attr("disabled",true);
                     $("#ngChRdo").attr("disabled",true);
                }else {
                    $("#okOfRdo").attr("disabled",false);
                    $("#ngChRdo").attr("disabled",false);
                }
            }
        },
        login_func: function () {
            var inObj, outObj, iary;
            var lot_id = domObj.BatchNoIn.val().trim();
            var opeIdfk = domObj.$opeIdFk.val().trim();
            var toolIdFk = domObj.$toolIdFk.val().trim();

            if (!opeIdfk) {
                showErrorDialog("", "站点代码不能为空");
                return false;
            }
            if (!toolIdFk) {
                showErrorDialog("", "设备代码不能为空");
                return false;
            }
            if (!lot_id) {
                showErrorDialog("", "Bathc No不能为空");
                return false;
            }
            iary = {
                lot_id: lot_id,
                ope_id_fk: opeIdfk,
                tool_id_fk: toolIdFk
            }
            inObj = {
                trx_id: VAL.T_FPPMOVEIN,
                evt_usr: VAL.EVT_USER,
                action_flg: 'F',
                iary: [iary]
            };
            outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                toolFunc.query_func();
                toolFunc.clean_func();
                showSuccessDialog("入账成功");
            }

        },
        reg_func: function () {
            var inObj, outObj, iary;
            var prd_seq_id = $.trim(domObj.prdIdReg.val());
            if (!prd_seq_id) {
                showErrorDialog("", "屏体代码不能为空");
                return false;
            }
            var batchCnt = domObj.BatchCntReg.val();
            if (!batchCnt) {
                showErrorDialog("", "请先查询屏体ID");
                return false;
            }
            var testCate = "D";
            if (domObj.tpRdo.attr("checked") == "checked") {
                testCate = "T";
            } else if (domObj.dxRdo.attr("checked") == "checked") {
                testCate = "D";
            } else if (domObj.wgRdo.attr("checked") == "checked") {
                testCate = "W";
            }
            var prd_judge = "NG";
            if (domObj.okRegRdo.attr("checked") == "checked") {
                prd_judge = "OK";
            } else if (domObj.ngRegRdo.attr("checked") == "checked") {
                prd_judge = "NG";
            }
            var defect_code = domObj.$defectCode.val();
            if (prd_judge == "NG" && !defect_code) {
                showErrorDialog("", "请选择不良代码");
                return false;
            }
            iary = {
                prd_seq_id: prd_seq_id,
                prd_judge: prd_judge,
                test_cate: testCate,
                defect_code: defect_code,
            }
            inObj = {
                trx_id: VAL.T_FPPMOVEOUT,
                evt_usr: VAL.EVT_USER,
                action_flg: 'R',
                iary: [iary]
            };
            outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                toolFunc.queryCnt_func();
                domObj.prdIdReg.val("");
                domObj.prdIdReg.focus();
                showMessengerSuccessDialog('登记成功',1)
            }
        },
        logof_func: function () {
            var inObj, outObj, iary,prdStat;
            var lot_id = $.trim(domObj.BatchNoOf.val());
            if (!lot_id) {
                showErrorDialog("", "Lot No不能为空");
                return false;
            }
            if (domObj.okOfRdo.prop('checked')) {//出账到包装

                var dxTestCnt = $.trim(domObj.dxTestCntOf.val());
                var wgTestCnt = $.trim(domObj.wgTestCntOf.val());
                var data =  domObj.grids.$chPrdListGrd.jqGrid("getRowData");
                //有NG不可出账
                for(var i = 0; i < data.length; i++){
                    if("NG" === data[i].ext_4 || "NG" === data[i].ext_6){
                        showErrorDialog("", "该批次中含有NG状态的屏体，不能出账！");
                        return false;
                    }
                }

                var inObj = {
                    trx_id: VAL.T_FIPINQSHT,
                    action_flg: 'Q',
                    prd_seq_id: data[0].prd_seq_id
                };
                var outObj = comTrxSubSendPostJson(inObj);
                if (outObj.rtn_code == VAL.NORMAL) {
                    if(parseInt(outObj.smp_cnt)>parseInt(wgTestCnt) || parseInt(outObj.smp_cnt)>parseInt(dxTestCnt)){
                        domObj.logof_btn.showCallBackWarnningDialog({
                            errMsg  : "电讯和外观检测数量小于应检数量,请确认!!!!",
                            callbackFn : function(data) {
                                if(data.result==true){
                                    iary = {
                                        lot_id: lot_id,
                                    }
                                    inObj = {
                                        trx_id: VAL.T_FPPMOVEOUT,
                                        evt_usr: VAL.EVT_USER,
                                        action_flg: 'F',
                                        iary: [iary]
                                    };
                                    outObj = comTrxSubSendPostJson(inObj);
                                    if (outObj.rtn_code == VAL.NORMAL) {
                                        toolFunc.clean_func();
                                        showSuccessDialog("出账成功");
                                    }
                                }
                            }
                        });
                    }else{
                        iary = {
                            lot_id: lot_id,
                        }
                        inObj = {
                            trx_id: VAL.T_FPPMOVEOUT,
                            evt_usr: VAL.EVT_USER,
                            action_flg: 'F',
                            iary: [iary]
                        };
                        outObj = comTrxSubSendPostJson(inObj);
                        if (outObj.rtn_code == VAL.NORMAL) {
                            toolFunc.clean_func();
                            showSuccessDialog("出账成功");
                        }
                    }
                    /*if(parseInt(outObj.smp_cnt)>parseInt(dxTestCnt)){
                        showErrorDialog("", "电讯检测数量小于应检数量");
                        return false;
                    }
                    if(parseInt(outObj.smp_cnt)>parseInt(wgTestCnt)){
                        showErrorDialog("", "外观检测数量小于应检数量");
                        return false;
                    }*/
                }
            }else if(domObj.ngOfRdo.prop('checked')){//批退操作
                var nxOpe = domObj.$chOpeIdFk.val();
                var nxOpeId = domObj.$chOpeIdFk.find("option:selected").text();
                var nxOpeiD = nxOpeId.split(":");
                if(!nxOpe){
                    showErrorDialog("", "请选择下一站点");
                    return false;
                }
                iary = {
                    lot_id: lot_id,
                    reOpe: nxOpe,
                    reOpe_id: nxOpeiD[0]
                }
                inObj = {
                    trx_id: VAL.T_FPPMOVEOUT,
                    evt_usr: VAL.EVT_USER,
                    action_flg: 'F',
                    iary: [iary]
                };
                outObj = comTrxSubSendPostJson(inObj);
                if (outObj.rtn_code == VAL.NORMAL) {
                    toolFunc.clean_func();
                    showSuccessDialog("批退成功");
                }
            }else{
                showErrorDialog("", "请选择出账到包装或者批退操作");
                return false;
            }
        },
        defectCodeDialogFnc: function () {
            domObj.dialogs.$defectListGrd
                .jqGrid("clearGridData");
            // 缺陷代码对话框的模型
            domObj.dialogs.$DFCodeDialog.modal({
                backdrop: true,
                keyboard: false,
                show: false
            });
            domObj.dialogs.$DFCodeDialog.modal("show");
            var inObj = {
                trx_id: VAL.T_FBPBISDAT,
                action_flg: "Q",
                iary: [{
                    data_cate: 'DFCT',
                  /*  ext_1: domObj.$opeIdFk.val().trim()*/
                }]
            };
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                setGridInfo(outObj.oary, "#defectListGrd");
            }
        },
        dialogSureFnc: function () {
            var id = $('#defectListGrd').jqGrid('getGridParam', 'selrow');
            var rowData = domObj.dialogs.$defectListGrd.jqGrid("getRowData", id);
            if (rowData.length == 0) {
                showErrorDialog("", "缺陷代码不能为空");
                return false;
            }
            domObj.$defectCode.val(rowData.data_id);
            domObj.dialogs.$DFCodeDialog.modal("hide");
        },
        prdChange_func: function () {
            var prdSeqId = $.trim(domObj.chPrdSeqId.val());
            if(!prdSeqId){
                showErrorDialog("", "请输入换片的屏体ID");
                return false;
            }
            var id = domObj.grids.$chPrdListGrd.jqGrid("getGridParam","selrow");
            if (id==null) {
                showErrorDialog("", "请选择屏体列表中需要换片的屏体信息");
                return false;
            }
            var rowData = domObj.grids.$chPrdListGrd.jqGrid("getRowData",id);
            if(prdSeqId==rowData.prd_seq_id){
                showErrorDialog("", "换片和被换的屏体不能是同一片!");
                return false;
            }
            var inObj = {
                trx_id: VAL.T_FIPINQSHT,
                action_flg: 'Q',
                prd_seq_id: prdSeqId
            };
            //先把输入的屏体入账，然后选择屏体取消入账（带上lotId）,把列表信息进行更新
            var outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == VAL.NORMAL) {
                if(outObj.toolg_id_fk!= "$FQC") {
                    showErrorDialog("", "ID["+prdSeqId+"]屏体不在FQC站点");
                    return false;
                }
                if(outObj.lot_id!=null){
                    showErrorDialog("", "ID["+prdSeqId+"]屏体已经组过批次");
                    return false;
                }
                if (outObj.prd_stat != "INPR") {//自动入账
                    var lot_id   = $.trim(domObj.BatchNoOf.val());
                    var opeIdfk  = $.trim(domObj.$opeIdFk.val());
                    var toolIdFk = $.trim(domObj.$toolIdFk.val());
                    var wo_id_fk = $.trim(domObj.$woIdFk.val());
                    iary = {
                        lot_id: lot_id,
                        wo_id_fk   : wo_id_fk,
                        ope_id_fk  : opeIdfk,
                        tool_id_fk : toolIdFk,
                        prd_seq_id : prdSeqId,
                    }
                    inObj = {
                        trx_id: VAL.T_FPPMOVEIN,
                        evt_usr: VAL.EVT_USER,
                        action_flg: 'A',
                        iary: [iary]
                    };
                    outObj = comTrxSubSendPostJson(inObj);
                    if (outObj.rtn_code == VAL.NORMAL) {

                    }
                }
                var iaryA = new Array();//被换的屏体取消入账
                iaryA.push({
                    prd_seq_id:rowData.prd_seq_id,
                    lot_id: lot_id
                });
                var inTrxObj ={
                    trx_id     : VAL.T_FPPMVINCCL,
                    action_flg : 'C',
                    evt_usr	: VAL.EVT_USER,
                    prd_qty    : iaryA.length,
                    iary	: iaryA,
                    opi_ope_flg: "Y",
                    back_flg  : "Y" //单片退回flag
                };
                var  outTrxObj = comTrxSubSendPostJson(inTrxObj);
                if(  outTrxObj.rtn_code == VAL.NORMAL ) {//查询入账后信息
                    var inObj = {
                        trx_id: VAL.T_FIPINQSHT,
                        action_flg: 'Q',
                        prd_seq_id: prdSeqId
                    };
                    var outObj = comTrxSubSendPostJson(inObj);
                    if (outObj.rtn_code == VAL.NORMAL) {
                        domObj.grids.$chPrdListGrd.jqGrid("delRowData", id);
                        domObj.grids.$chPrdListGrd.jqGrid("addRowData", id, outObj);
                    }
                }

            }
        },
    }
    function initNxOpe() {

        var path_id = $.trim(domObj.$pathId.val());
        var path_ver = "00000";
        if(!path_id){
            showErrorDialog("", "请先查询屏体信息");
            return false;
        }
        var iary ={
            path_id : path_id,
            path_ver: path_ver,
        };
        var inObj={
            trx_id      : VAL.T_FBPBISPTH ,
            action_flg  : "Q"        ,
            iaryA        : [iary]
        };
        var outObj = comTrxSubSendPostJson(inObj);
        if (outObj.rtn_code == VAL.NORMAL) {
            // SelectDom.addSelectArr_(domObj.$chOpeIdFk,outObj.oaryB,"cr_ope_no","cr_ope_id_fk","cr_ope_desc",true);
            domObj.$chOpeIdFk.empty();
            var options = [];
            domObj.$chOpeIdFk.append("<option ></option>");
            for(var i=0; i<outObj.oaryB.length; i++){
                var cr_ope_no = outObj.oaryB[i]["cr_ope_no"];
                if(parseInt(cr_ope_no)<parseInt(ope_no)){
                    options[i] = "<option value ="+ outObj.oaryB[i]["cr_ope_no"] +">"+ outObj.oaryB[i]["cr_ope_id_fk"] +":"+outObj.oaryB[i]["cr_ope_desc"]+ "</option>";
                }
            }
            domObj.$chOpeIdFk.append(options.join(""));
            domObj.$chOpeIdFk.select2({
                theme : "bootstrap"
            });
           /* toolFunc.addSelectArr(domObj.chOpeIdFk, outObj.oaryB, "cr_ope_no", "cr_ope_id_fk", "", true);*/
        }
    }
    var initializationFunc = function () {
        initInner();
    };
    initializationFunc();
    domObj.query_btn.click(function () {
        toolFunc.query_func();
    });
    domObj.reg_btn.click(function () {
        toolFunc.reg_func();
    });
    domObj.login_btn.click(function () {
        toolFunc.login_func();
    });
    domObj.logof_btn.click(function () {
        toolFunc.logof_func();
    });
    domObj.$defectCode.focus(function () {
        domObj.$defectCode.val("");
        toolFunc.defectCodeDialogFnc();
    });
    domObj.prdIdIn.keydown( function (event) {
        if (event.keyCode == 13) {
            toolFunc.query_func();
        }
    });
    domObj.prdIdReg.keydown( function (event) {
        if (event.keyCode == 13) {
            toolFunc.queryCnt_func();
        }
    });
    domObj.prdIdOf.keydown( function (event) {
        if (event.keyCode == 13) {
            toolFunc.queryOf_func();
        }
    });
    domObj.chPrdSeqId.keydown( function (event) {
        if (event.keyCode == 13) {
            toolFunc.prdChange_func();
        }
    });
    domObj.okRegRdo.click(function () {
        domObj.$defectCode.attr(VAL.DISABLED_ATTR);
    });
    domObj.ngRegRdo.click(function () {
        domObj.$defectCode.attr(VAL.ENABLED_ATTR);
    });
    domObj.okOfRdo.click(function () {
        domObj.chPrdSeqId.attr(VAL.DISABLED_ATTR);
        domObj.$chOpeIdFk.attr(VAL.DISABLED_ATTR);
    });
    domObj.ngChRdo.click(function () {
        domObj.chPrdSeqId.attr(VAL.ENABLED_ATTR);
        domObj.$chOpeIdFk.attr(VAL.DISABLED_ATTR);
    });
    domObj.ngOfRdo.click(function () {
        initNxOpe();
        domObj.chPrdSeqId.attr(VAL.DISABLED_ATTR);
        domObj.$chOpeIdFk.attr(VAL.ENABLED_ATTR);
    });
    domObj.dialogs.$defectCode_sureBtn.click(function () {
        toolFunc.dialogSureFnc();
    });
    domObj.tpRdo.click(function () {
        domObj.BatchCntReg.val("");
        domObj.TestCntReg.val("");
        domObj.abnCntReg.val("");
        domObj.okRegRdo.attr("checked", true);
        domObj.$defectCode.attr(VAL.DISABLED_ATTR);
    });
    domObj.dxRdo.click(function () {
        domObj.BatchCntReg.val("");
        domObj.TestCntReg.val("");
        domObj.abnCntReg.val("");
        domObj.okRegRdo.attr("checked", true);
        domObj.$defectCode.attr(VAL.DISABLED_ATTR);
    });
    domObj.wgRdo.click(function () {
        domObj.BatchCntReg.val("");
        domObj.TestCntReg.val("");
        domObj.abnCntReg.val("");
        domObj.okRegRdo.attr("checked", true);
        domObj.$defectCode.attr(VAL.DISABLED_ATTR);
    });

    //表格自适应
    function resizeFnc() {
        var offsetBottom, grdDivWidth;
        grdDivWidth = $("#divTop").width();
        offsetBottom = $(window).height() - $("#prdListDiv").offset().top;

        $("#prdListDiv").width(grdDivWidth * 0.98);
        $("#prdListDiv").height(offsetBottom * 0.99);
        $("#prdListDiv").setGridWidth(grdDivWidth * 0.97);
        $("#prdListGrd").setGridHeight(offsetBottom * 0.95 - 51);
    };
    //resizeFnc();
    $(window).resize(function () {
        resizeFnc();
    });
});
